package com.xunbao.utils;

import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * ClassName:TypeConvertUtil
 * Description: 类型转换工具类
 * Author:yijiawei
 * Date: 2016/4/27 9:26
 */
public class TypeConvertUtil {

    /**
     * 将对象转换成Map
     *
     * @param obj 对象
     * @return Map
     */
    public static Map<String, String> toHashMap(Object obj) {
        Map<String, String> data = new HashMap<String, String>();
        JSONObject jsonObject = JSONObject.fromObject(obj);
        Iterator it = jsonObject.keys();
        while (it.hasNext()) {
            String key = String.valueOf(it.next());
            String value = String.valueOf(jsonObject.get(key));
            if (StringUtils.isBlank(value)) {
                continue;
            }
            data.put(key, value);
        }
        return data;
    }


    public static void main(String[] args) {

    }
}
